package com.ruoyi.web.controller.accountingBookSettings;


import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.AccountingExpenseCategories;
import com.ruoyi.system.service.IAccountingExpenseCategoriesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 记账本支出类型，定义支出类别及其属性 Controller
 *
 * @author ruoyi
 * @date 2025-05-13
 */
@Api(tags="记账本支出类型")
@RestController
@RequestMapping("/system/accountingExpenseCategories")
public class AccountingExpenseCategoriesController extends BaseController
{
    @Autowired
    private IAccountingExpenseCategoriesService accountingExpenseCategoriesService;

    /**
     * 查询记账本支出类型列表
     */
    @ApiOperation("查询记账本支出类型列表")
    @PreAuthorize("@ss.hasPermi('system:categories:list')")
    @GetMapping("/list")
    public TableDataInfo list(AccountingExpenseCategories accountingExpenseCategories)
    {
        startPage();
        List<AccountingExpenseCategories> list = accountingExpenseCategoriesService.selectAccountingExpenseCategoriesList(accountingExpenseCategories);
        return getDataTable(list);
    }

    /**
     * 导出记账本支出类型列表
     */
    @ApiOperation("导出记账本支出类型列表")
    @PreAuthorize("@ss.hasPermi('system:categories:export')")
    @Log(title = "记账本支出类型，定义支出类别及其属性", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AccountingExpenseCategories accountingExpenseCategories)
    {
        List<AccountingExpenseCategories> list = accountingExpenseCategoriesService.selectAccountingExpenseCategoriesList(accountingExpenseCategories);
        ExcelUtil<AccountingExpenseCategories> util = new ExcelUtil<AccountingExpenseCategories>(AccountingExpenseCategories.class);
        util.exportExcel(response, list, "记账本支出类型");
    }

    /**
     * 通过id获取记账本支出类型信息
     */
    @ApiOperation("通过id获取记账本支出类型信息")
    @PreAuthorize("@ss.hasPermi('system:categories:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(accountingExpenseCategoriesService.selectAccountingExpenseCategoriesById(id));
    }

    /**
     * 新增记账本支出类型
     */
    @ApiOperation("新增记账本支出类型")
    @PreAuthorize("@ss.hasPermi('system:categories:add')")
    @Log(title = "记账本支出类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AccountingExpenseCategories accountingExpenseCategories)
    {
        return toAjax(accountingExpenseCategoriesService.insertAccountingExpenseCategories(accountingExpenseCategories));
    }

    /**
     * 修改记账本支出类型
     */
    @ApiOperation("修改记账本支出类型")
    @PreAuthorize("@ss.hasPermi('system:categories:edit')")
    @Log(title = "记账本支出类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AccountingExpenseCategories accountingExpenseCategories)
    {
        return toAjax(accountingExpenseCategoriesService.updateAccountingExpenseCategories(accountingExpenseCategories));
    }

    /**
     * 通过id批量删除记账本支出类型信息
     */
    @ApiOperation("通过id批量删除记账本支出类型信息")
    @PreAuthorize("@ss.hasPermi('system:categories:remove')")
    @Log(title = "记账本支出类型", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(accountingExpenseCategoriesService.deleteAccountingExpenseCategoriesByIds(ids));
    }
}
